package TamirsGui;

import java.util.Vector;

public class ServerMsg implements CreateMsgToServer{
	public static final String delimiter =  ((char)1)+"";
	private final String endOfMessage;
	public ServerMsg(){
		
		endOfMessage = "\n\0\n";
	}
	
	private String getUserLocation(Vector<String> path) {
		String location = "";
		for (String loc : path) {
			location +=loc+delimiter;
		}
		return location;
	}
	private String getUserSubForumId(Vector<String> path){
		String location = "";
		location +=path.elementAt(0);
		return location;
	}
	private String getUserSubForumIdAndThreadID(Vector<String> path){
		String location = "";
		location +=path.elementAt(0)+delimiter;
		location +=path.elementAt(1)+delimiter;
		return location;
	}
	
	
	
	@Override
	public String getRegisterMsg(String userName, String password) {
		String serverMsg = "register"+delimiter+userName+delimiter+password+delimiter+endOfMessage;
		return serverMsg;
	}

	@Override
	public String getLoginMsg(String userName, String password) {
		String serverMsg = "login"+delimiter+userName+delimiter+password+delimiter+endOfMessage;
		return serverMsg;
	}

	@Override
	public String getViewForumMsg() {
		String serverMsg = "viewForum"+delimiter+endOfMessage;
		return serverMsg;

	}
                    @Override
	public String getViewForumMsg(String userName) {
		String serverMsg = "viewForum"+delimiter+userName+delimiter+endOfMessage;
		return serverMsg;

	}



	@Override
	public String getLogoutMsg(String userName) {
		String serverMsg = "logout"+delimiter+userName+delimiter+endOfMessage;
		return serverMsg;

	}

	@Override
	public String getViewSubForumMsg(String userName, Vector<String> path) {
            
		String userLocation = this.getUserLocation(path);
                System.out.println(userLocation);
		String serverMsg = "viewSubForum"+delimiter+userName+delimiter+userLocation+endOfMessage;
                System.out.println("viewSub "+serverMsg);
		return serverMsg;
	}
	@Override
	public String getViewThreadMsg(String userName, Vector<String> path) {
		String userLocation = this.getUserLocation(path);
		String serverMsg = "viewThread"+delimiter+userName+delimiter+userLocation+endOfMessage;
		return serverMsg;
	}

	@Override
	public String getModeratorsCandidateMsg(String userName, Vector<String> path) {
		String userLocation = this.getUserLocation(path);
		int firstDelimiter = userLocation.indexOf(this.delimiter);
		String subForumId = userLocation.substring(0, firstDelimiter);
		String serverMsg = "ModeratorsCandidate"+delimiter+userName+delimiter+subForumId+delimiter+endOfMessage;
		return serverMsg;
	}
	@Override
	public String getModeratorsCandidateMsg(String userName, String subForumId) {
		String userLocation = subForumId;
		String serverMsg = "ModeratorsCandidate"+delimiter+userName+delimiter+userLocation+delimiter+endOfMessage;
		return serverMsg;
	}
	@Override
	public String getAddModeratorMsg(String userName, String moderatorUserName,
			Vector<String> path) {
		String subForumId = path.elementAt(0);
		String serverMsg = "AddModerator"+delimiter+userName+delimiter+moderatorUserName+delimiter+subForumId+delimiter+endOfMessage;
		return serverMsg;
	}
	@Override
	public String getDeleteMsg(String userName, Vector<String> path,boolean isThread) {
		String userLocation = this.getUserLocation(path);
		String serverMsg = "deleteMsg"+delimiter+userName+delimiter+userLocation+ isThread
                                            +delimiter+endOfMessage;
		return serverMsg;
	}
	public String getDeleteMsg(String userName, Vector<String> path,String currentMessageId) {
		String userLocation = this.getUserLocation(path);
		String serverMsg = "deleteMsg"+delimiter+userName+delimiter+userLocation+currentMessageId+delimiter+endOfMessage;
		return serverMsg;
	}
	@Override
	public String getEditMsg(String userName, Vector<String> path,boolean isThread) {
		String userLocation = this.getUserLocation(path);
		String serverMsg = "EditMsg"+delimiter+userName+delimiter+userLocation+ isThread
                                            +delimiter+endOfMessage;
		return serverMsg;
	}
                    @Override
	public String getEditMsg(String userName, Vector<String> path,String subject,String content,boolean isThread) {
		String userLocation = this.getUserLocation(path);
		String serverMsg = "EditMsg"+delimiter+userName+delimiter+userLocation+subject+delimiter+content+delimiter+ isThread
                                            +delimiter+endOfMessage;
		return serverMsg;
	}
	public String getEditMsg(String userName, Vector<String> path,String currentMessageId,String subject,String content) {
		String userLocation = this.getUserLocation(path);
		String serverMsg = "EditMsg"+delimiter+userName+delimiter+userLocation+currentMessageId+delimiter+subject+delimiter+content+delimiter+endOfMessage;
		return serverMsg;
	}
	@Override
	public String getRemoveModerator(String userName, String moderatorUserName,
			Vector<String> path) {
		String subForumId = path.elementAt(0);
		String serverMsg = "removeModerator"+delimiter+userName+delimiter+subForumId+delimiter+moderatorUserName+delimiter+endOfMessage;
		return serverMsg;
	}
	@Override
	public String getModerators(String userName, Vector<String> path) {
		String userLocation = this.getUserLocation(path);
		int firstDelimiter = userLocation.indexOf(this.delimiter);
		String subForumId = userLocation.substring(0, firstDelimiter+1);
		String serverMsg = "getModerators"+delimiter+userName+delimiter+subForumId+endOfMessage;
		return serverMsg;
	}
//	@Override
//	public String getSubForumMsg(String userName, String subForumName) {
//		// TODO Auto-generated method stub
//		return null;
//	}
	@Override
	public String exit(String userName) {
		String serverMsg = "bye"/*+userName+delimiter+*/ +endOfMessage;
		return serverMsg;
	}
	@Override
	 public String getAddThreadMsg(String userName,Vector<String> path,String subject,String content){
		String userLocation = this.getUserSubForumId(path);
		String message = "addThread"+delimiter+userName+delimiter+userLocation+delimiter+subject+delimiter+content+delimiter+endOfMessage;
                                            System.out.println(message);
		return message;
		
	}
	@Override
	 public String getAddPostdMsg(String userName,Vector<String> path,String subject,String content,boolean isThread){
		String userLocation = getUserLocation(path);
		String message = "addPost"+delimiter+userName+delimiter+userLocation+subject+delimiter+content+delimiter+ isThread
                                            +delimiter+endOfMessage;
		return message;
		
	}
	public String replayToAPost(String userName,Vector<String> path,String subject,String content){
		String userLocation = getUserLocation(path);
		String message = "addPost"+delimiter+userName+delimiter+userLocation+delimiter+subject+delimiter+content+delimiter+endOfMessage;
		return message;
		
	}

	@Override
	public String getAddSubForum(String userName, String subForumName) {
		String message = "addSubForum"+delimiter+userName+delimiter+subForumName+delimiter+endOfMessage;
		return message;
	}

	@Override
	public String getRemoveSubForum(String userName, String subformId) {
		String message = "DeleteSubForum"+delimiter+userName+delimiter+subformId+delimiter+endOfMessage;
		return message;
	}
	@Override
	public  String getNumOfMessagesInSubForum(String userName,Vector<String> path){
		String subForumId = path.elementAt(0);
		String message = "numOfMsgs"+delimiter+userName+delimiter+subForumId+delimiter+endOfMessage;
		return message;
	}
	@Override
	public String getNumOfMessageByUser(String userName){
		String message = "msgsByUser"+delimiter+userName+delimiter+endOfMessage;
		return message;
	}
	@Override
	public String getMsgCount(String userName,String userToSearch){
		String message = "msgCount"+delimiter+userName+delimiter+userToSearch+delimiter+endOfMessage;
		return message;
	}

    public String getAdminsCandidateList(String userName)
    {
        String message = "adminCandidate" + delimiter + userName + delimiter + endOfMessage;
          return message;
    }

    public String getChangeAdmin(String userName, String moderatorName) {
        String msg = "changeAdmin" + delimiter + userName + delimiter + moderatorName + delimiter + endOfMessage;
        return msg;
    }

    public String getNumOfConnection(String userName) {
        String msg = "numOfConnection" + delimiter + userName + delimiter + endOfMessage;
        return msg;
    }
    
    
	

}
